<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core">

<ui:composition template="/WEB-INF/template/basicTemplate.xhtml">
	<ui:define name="content">
	<h:inputHidden rendered="#{menuController.userRank != 0}" value="#{menuController.redirect()}"></h:inputHidden>
	<h:inputHidden value="#{menuController.setUrl(request.requestURL)}"></h:inputHidden>
		<h:inputHidden rendered="#{menuController.userRank == 0}">
			<h:messages id="delmessages" styleClass="#{qController.messageClass}"></h:messages>
		<h:panelGrid columns="2" border="1">
			<h:column>
				<h:form styleClass="colvalquestionscategory">
				<h:outputText value="Domain:" styleClass="dropListDomainTitle"></h:outputText>
					<h:selectOneMenu
						valueChangeListener="#{domainController.changeSelected}"
						styleClass="dropdownlist" onchange="submit()">
						<f:selectItems value="#{domainController.listOfD}" var="domain"
							itemValue="#{domain.id}" itemLabel="#{domain.name}"></f:selectItems>
					</h:selectOneMenu>
				</h:form>
				<br />
				<h:form id="formCat"
					rendered="#{categoryController.currentDomainId != -1}">
					<h:panelGrid width="100%" styleClass="inner-table">

						<h:dataTable id="tableCat"
							value="#{categoryController.listOfCategories}" var="item"
							border="10" width="100%" styleClass="inner-table">
							<h:column>
								<f:facet name="header">
									<h:outputText value="Category" />
								</f:facet>
								<div align="center"><h:commandLink value="#{item.name}"
									style="#{(item.id eq qController.currentCategoryId)?'color: red':'color: default'}">
									<f:setPropertyActionListener value="#{item.id}"
										target="#{qController.currentCategoryId}"></f:setPropertyActionListener>
								</h:commandLink></div>
							</h:column>
						</h:dataTable>
						<h:panelGrid columns="2" width="auto" styleClass="inner-table">

						</h:panelGrid>

					</h:panelGrid>
				</h:form>
			</h:column>
			<h:column id="column2"
				rendered="#{qController.currentCategoryId != -1}">
				<h:form>
					<h:dataTable id="table" binding="#{qController.dataTable}" rows="5"
						value="${qController.allQuestions}" var="item"
						columnClasses="qFirst, qSecond, qThird">

						<h:column>
							<f:facet name="header">
								<h:outputText value="Status" />
							</f:facet>

							<h:selectManyCheckbox id="checkvalid"
								value="#{qController.checkboxValid}"
								title="Check to validate the question!" styleClass="inner-table">
								<f:selectItem itemLabel="Valid" itemValue="#{item.id}"
									itemDisabled="#{item.valid == 1}" />
							</h:selectManyCheckbox>
						</h:column>

						<h:column>
							<f:facet name="header">
								<h:outputText value="Questions and answers" />
							</f:facet>
							<h:outputText value="Question:" styleClass="questiontitle"></h:outputText>
							<div align="left"><h:outputText value="#{item.text}"
								styleClass="boldText" /></div>
							<br />
							<h:outputText value="Answers:" styleClass="answertitle"></h:outputText>
								<div align="left">
								<table class="inner-table auto">
									<ui:repeat var="ans" value="#{item.correctAnswerList}">
										<h:panelGroup>
											<tr>
												<td><h:graphicImage library="images" name="check.png"
													height="20" width="20"></h:graphicImage></td>
												<td>#{ans}</td>
											</tr>
										</h:panelGroup>
									</ui:repeat>
	
									<ui:repeat var="answ" value="#{item.allAnswerList}">
										<h:panelGroup>
											<tr>
												<td><h:graphicImage library="images" name="cross.png"
													height="20" width="20"></h:graphicImage></td>
												<td>#{answ}</td>
											</tr>
										</h:panelGroup>
									</ui:repeat>
								</table>
								</div>
							</h:column>
							
							<h:column>
								<h:commandButton value="Delete"
									onclick="if (!confirm('Are you sure you want to delete this?')) return false;"
									disabled="#{item.valid == 1}"
									action="#{qController.deleteInvalid(item)}"
									title="Delete this question!"
									binding="#{qController.deleteButton}"
									styleClass="#{(item.valid == 1) ? 'buttonDis' : 'button'}"></h:commandButton>
							</h:column>


						<f:facet name="footer">
								<h:panelGroup>
									<h:commandButton value="First" title="Go to the first page"
										actionListener="#{qController.pageFirst}"
										disabled="#{qController.dataTable.first == 0}"
										styleClass="#{qController.buttonFirstPrev}" />
									<h:commandButton value="Prev" title="Go to the previous page"
										actionListener="#{qController.pagePrevious}"
										disabled="#{qController.dataTable.first == 0}"
										styleClass="#{qController.buttonFirstPrev}" />
									<h:commandButton value="Next" title="Go to the next page"
										actionListener="#{qController.pageNext}"
										disabled="#{qController.dataTable.first + qController.dataTable.rows
	                        >= qController.dataTable.rowCount}"
										styleClass="#{qController.buttonNextLast}" />
									<h:commandButton value="Last"
									title="Go to the last page"
										actionListener="#{qController.pageLast}"
										disabled="#{qController.dataTable.first + qController.dataTable.rows
	                        >= qController.dataTable.rowCount}"
										styleClass="#{qController.buttonNextLast}" />
								</h:panelGroup>
							</f:facet>
						</h:dataTable>
	
						<h:commandButton binding="#{qController.validateButton}"
							actionListener="#{qController.validateQuestion}"
							title="Validate the questions!"
							styleClass="#{qController.buttonValidate}" value="Validate!">
						</h:commandButton>
					</h:form>

			</h:column>
		</h:panelGrid>
		</h:inputHidden>
	</ui:define>
</ui:composition>
</html>